using UniversalAdminSystem.Domian.Core.ValueObjects;

namespace UniversalAdminSystem.Domian.UserConversations.Aggregates;

public class Message
{
    public MessageId Id { get; private set; } = null!;

    public ConversationId ConversationId { get; private set; } = null!;

    public string Role { get; private set; } = null!;

    public string Content { get; private set; } = null!;

    public DateTime CreateDate { get; private set; }

    protected Message() { }

    private Message(MessageId id, ConversationId conversationId, string role, string content, DateTime time)
    {
        Id = id;
        ConversationId = conversationId;
        Role = role;
        Content = content;
        CreateDate = time;

    }

    public static Message Create(ConversationId conversationId, string role, string content)
    {
        if (role == null || role.Length == 0) throw new ArgumentException("角色不得为空");
        if (content == null || content.Length == 0) throw new ArgumentException("内容不得为空");
        return new Message(
            MessageId.Create(Guid.NewGuid()),
            conversationId,
            role,
            content,
            DateTime.UtcNow
        );
    }
}